<?PHP
   include ("../../Connections/cpsms.php");
   
   $username = $_POST['username'];
   $Loginname = $_POST['Loginname'];
   $password = $_POST['password'];
   $passwordagain = $_POST['passwordagain'];
   $PolicIDNo = $_POST['PolicIDNo'];
   $gender = $_POST['gender'];   
   $DOB = $_POST['DOB'];
   $Ethic = $_POST['Ethic'];
   $Political = $_POST['Political'];
   $Birthplace = $_POST['Birthplace'];
   $workDate = $_POST['workDate'];
   $ParthDate = $_POST['ParthDate'];
   $PlolicWorkDate = $_POST['PlolicWorkDate'];
   $CurrentPosition = $_POST['CurrentPosition'];
   $Rank = $_POST['Rank'];
   $FirstEducation = $_POST['FirstEducation'];
   $School = $_POST['School'];
   $HighestEducation = $_POST['HighestEducation'];
   $HighestAcademic = $_POST['HighestAcademic'];
   	$sql2 = mysql_query("select * from users where loginname='$Loginname';") or die(mysql_error());
	$count2 = mysql_num_rows($sql2);
   if($username != NULL and $Loginname != NULL and $password != NULL and $passwordagain != NULL 
      and $addstartdate != NULL and $gender != NULL and $DOB != NULL 
      and $Ethic != NULL and $CurrentPosition != NULL){
	  echo ("some * value your are not enter!!!");
	  echo "<script language='javascript'>location='RegisterUser.php?id=1';</script>";
	}else if($password != $passwordagain){
	  echo ("Password error!!!");
	  echo "<script language='javascript'>location='RegisterUser.php?id=4';</script>";
	}else if($count2 == 1){
   echo ("sorry this Loginname be used already!");
  echo "<script language='javascript'>location='RegisterUser.php?id=3';</script>";
   }else{
	  mysql_query("INSERT INTO cpsms.tempusers(tloginname, tloginpassword, tusername, `tPoliceIDNo`, `tGender`,
	  			 	  `tBirthplace`, `tDOB`, `tEthic`, `tPolitical`, `tPartyDate`, `tWorkDate`,`tPoliceWorkDate`,
			  		  `tCurrentPosition`, `tRank`, `tFirstEducation`,`tHighestEducation`, `tHighestAcademicInstitution`)
				  	 VALUES ('$Loginname','$password', '$username', '$PolicIDNo', '$gender','$Birthplace','$DOB',
					  '$Ethic','$Political', '$ParthDate', '$workDate', '$PlolicWorkDate', '$CurrentPosition', 
					  '$Rank', '$FirstEducation', '$HighestEducation', '$HighestAcademic');")
					  or die(mysql_error());
					
   session_start(); 
   $_SESSION['Loginname'] = $Loginname; // store session data
   echo "Pageviews = ". $_SESSION['Loginname']; //retrieve data
   echo "<script language='javascript'>";
   echo "location='../../view/User/userAutoInfo.php?id=$userArchiveid';";
   echo "</script>";				
   }	
	
	
	function getuserid($loginname){				
	  $query = "select * from tempusers where tloginname=$Loginname;";
	  $sql = mysql_query($query) or die(mysql_error());
	  $array = mysql_fetch_array($sql);
	  $userArchiveid = $array['tArchiveid'];
	  return $userArchiveid;
	}


   ?>
